﻿@{
    ViewBag.Title = "零仓合同";
    Layout = "~/Views/Shared/InfoMaste.cshtml";
}

<table id="dg" class="easyui-datagrid" style="width:100%; height: 750px;"
       url="/LKWarehouseContract/GetLKZeroWarehouseContractPageList" toolbar="#tb" title="零仓合同" rownumbers="true" pagination="true"
       pagelist="[10,15]" fitcolumns="true" singleselect="true">
    <thead>
        <tr>
            <th field="ContractNo" align="right" width="80">
                合同编号
            </th>
            @*<th field="CustomerName" align="right" width="80">
            客户
        </th>
        <th field="BeginTime" align="right" width="80" formatter="formatter_BeginTime">
            开始日期
        </th>
        <th field="EndTime" align="right" width="80" formatter="formatter_EndTime">
            结束日期
        </th>*@
            <th field="Days" align="right" width="80">
                天数
            </th>
            @*<th field="Cycle" align="right" width="80">
                周期
            </th>*@
            <th field="ColdAlgorithmName" align="right" width="80">
                冷藏算法
            </th>
            <th field="ChargingUnitName" align="right" width="80">
                计费单位
            </th>
            <th field="ColdUnitPrice" align="right" width="80" formatter="formatter_ColdUnitPrice">
                冷藏单价
            </th>
            <th field="ContractTime" align="right" width="80" formatter="formatter_ContractTime">
                开单日期
            </th>
            <th field="Remark" align="right" width="80">
                备注
            </th>
            <th field="IsValid" align="right" width="80" formatter="formatter_IsValid">
                是否停用
            </th>
            <th field="IsByTon" align="right" width="80" formatter="formatter_IsByTon">
                按吨操作
            </th>
            @*<th field="StatusName" align="right" width="80">
            状态
            </th>*@
        </tr>
    </thead>
</table>
<div id="tb" style="padding: 3px; height: auto;">
    <span>合同编号</span>
    <input id="ContractCode" class="easyui-textbox " style="width: 173px; height: 30px;" />
    <span>客户名称</span>
    <input type="hidden" id="hdselectKeyword" />
    <input name="SelectCustomer" id="SelectCustomer" class="easyui-combobox" style="width: 173px; height: 30px;" />
    <span>开始时间</span>
    <input class="easyui-datebox" name="BeginTime" id="BeginTime" style="width: 173px; height: 30px; ">
    <span>结束时间</span>
    <input class="easyui-datebox" name="EndTime" id="EndTime" style="width: 173px; height: 30px; ">
    <span>状态</span>
    <select id="IsValid" class="easyui-combobox" data-options="editable:false" style="width: 90px; height: 30px;">
        <option value="" selected="selected">全部</option>
        <option value="true">启用</option>
        <option value="false">停用</option>
    </select>
    <div>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addLKZeroWarehouseContract()">新建</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editLKZeroWarehouseContract()">编辑</a>
        <a href="javascript:" class="easyui-linkbutton" iconcls="icon-no" plain="true" onclick="delLKZeroWarehouseContract()">删除</a>
        <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="doSearch()">查询</a>
    </div>
</div>
<div id="dlg" class="easyui-dialog" title="新增" data-options="iconCls:'icon-save'"
     closed="true" style="width: 100%; height: 600px; padding: 10px 20px" buttons="#dlg-buttons" modal="true">
    <form id="fm" method="post" novalidate class="border: 1px solid #ccc;padding: 10px;">
        <input type="hidden" name="Id" />
        <input type="hidden" name="IsValid" />
        <input type="hidden" name="ContractNo" />
        <div class="fitem">
            <label>
                客户编号:
            </label>
            <select class="easyui-combogrid" style="width:300px; height: 30px;" name="CustomerId" id="CustomerId"></select>
            <input type="hidden" id="hdKeyword" />
            <label>
                客户名称:
            </label>
            <input name="CustomerName" id="CustomerName" class="easyui-textbox" style="width: 300px; height: 30px;" readonly="readonly" />
            <label>
                开单日期:
            </label>
            <input class="easyui-datebox" name="ContractTime" id="ContractTime" style="width: 300px; height: 30px; " data-options="required:true">
        </div>
        <div class="fitem">
            <label>
                开始日期:
            </label>
            <input class="easyui-datebox" name="BeginTime" id="BeginTime" style="width: 300px; height: 30px; " data-options="required:true">
            <label>
                结束日期:
            </label>
            <input class="easyui-datebox" name="EndTime" id="EndTime" style="width: 300px; height: 30px; " data-options="required:true">
            <label>
                不足n吨算n吨:
            </label>
            <input name="Tonnage" id="Tonnage" class="easyui-numberbox" data-options="required: true" style="width: 300px; height: 30px;" autocomplete="off" />
            <label>
                按吨操作:
            </label>
            <input class="easyui-switchbutton" id="sbIsByTon" data-options="onText:'是',offText:'否'">
        </div>
        <div class="fitem">
            <label>
                计费单位:
            </label>
            <input name="ChargingUnit" id="ChargingUnit" class="easyui-combobox" style="width: 300px; height: 30px;" />
            <label>
                冷藏单价:
            </label>
            <input name="ColdUnitPrice" id="ColdUnitPrice" class="easyui-numberbox" data-options="required: true,precision:'2'" style="width: 300px; height: 30px;" autocomplete="off" />
            <label>
                冷藏算法
            </label>
            <input name="ColdAlgorithm" id="ColdAlgorithm" class="easyui-combobox" style="width: 300px; height: 30px;" />
            <label>
                周期:
            </label>
            <input name="Cycle" id="Cycle" class="easyui-textbox" style="width: 300px; height: 30px;" />
        </div>
        <div class="fitem">
            <label>
                备注:
            </label>
            <textarea rows="4" cols="4" style="width: 1200px; height: 90px; vertical-align: top" name="Remark" id="Remark" autocomplete="off" placeholder="200字以内"></textarea>
        </div>
    </form>

</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveLKZeroWarehouseContract()">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
</div>
<div id="customerselecttoolbar">
    <input id="SelectCustomerText" class="easyui-textbox " style="width: 173px; height: 30px;" />
    <a href="javascript:" class="easyui-linkbutton" plain="true" iconcls="icon-search" onclick="querycustomer()">查询</a>
</div>

<script src="~/Js/Global.js"></script>
<script language="javascript" type="text/javascript">
    $(function () {
        InitSelectCustomer();
    });

    $('#dg').datagrid({
        // 其他配置...
        onDblClickRow: function (rowIndex, rowData) {
            editLKZeroWarehouseContract();
        }
    });

    function addLKZeroWarehouseContract() {
        window.location.href = "/LKWarehouseContract/AddLKZeroWarehouseContract";
    }

    function InitChargingUnitCombobox() {
        $('#ChargingUnit').combobox({
            url: "/LkGlobal/GetChargeUnitList",
            valueField: 'Value',
            textField: 'Description',
            onSelect: function (rec) {
                //$('#ChargingUnit').combobox("setValue", rec.Value);
            }
        });
    }

    //function InitColdAlgorithmCombobox() {
    //    $('#ColdAlgorithm').combobox({
    //        url: "/LkGlobal/GetColdAlgorithmList",
    //        valueField: 'Value',
    //        textField: 'Description',
    //        onSelect: function (rec) {
    //            //$('#ColdStorage').combobox("setValue", rec.Value);
    //        }
    //    });
    //}
    //function checkDecimal(newValue, oldValue) {
    //    if (newValue.toString().split('.').length > 1) {
    //        var decimalPart = newValue.toString().split('.')[1];
    //        if (decimalPart.length > 2) {
    //            alert(22);
    //            //$.messager.alert('Warning', '超过两位小数！');
    //            $(this).numberbox('setValue', oldValue);
    //        }
    //    }
    //}
    //function setFixRate() {
    //    //	var value = $('._fixRate').numberbox('getValue');//不能使用numberbox的getValue,这个是隐藏框的值
    //    //如果有小数点
    //    var value = $('#Balance').val();//这个才是输入框的值
    //    if (value.indexOf(".") >= 0) {//如果包含小数点
    //        if ((value.substring(value.indexOf(".") + 1).length) >= 2) {//如果小数位数已经有两位
    //            //			window.event.returnValue = false;
    //            //			$('._fixRate').val(value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'));
    //            //			$('._fixRate').numberbox('filter',false);
    //            $('#Balance').numberbox('options').filter = function () {
    //                //让filter返回false会禁止按键输入
    //                return false;
    //            };
    //        } else {
    //            //记得写else,否则该nunberbox将不允许再次输入了
    //            $('#Balance').numberbox('options').filter = function () {
    //                return true;
    //            }
    //        }
    //    }
    //}

    function doSearch() {
        $('#dg').datagrid('load', {
            ContractNo: $('#ContractCode').val(),
            CustomerId: $('#SelectCustomer').combobox('getValue'),
            IsValid: $('#IsValid').combobox('getValue'),
            BeginTime: $('#BeginTime').datebox('getValue'),
            EndTime: $('#EndTime').datebox('getValue'),
        });
    }

    //function InitCustomer() {
    //    $('#CustomerId').combogrid({
    //        url: "/Customer/GetCustomerPageList",
    //        method: 'post',
    //        mode: 'remote',
    //        pageSize: 15,               //每页显示的记录条数，默认为10
    //        pageList: [10, 15, 20],       //可以设置每页记录条数的列表
    //        pagination: true,
    //        panelWidth: 500,
    //        toolbar: "#customerselecttoolbar2",
    //        idField: 'Id',
    //        textField: 'CustomerCode',
    //        onSelect: function () {
    //            var g = $('#CustomerId').combogrid('grid');
    //            var row = g.datagrid('getSelected');
    //            $('#CustomerId').combogrid("setValue", row.Id);
    //            $('#CustomerName').textbox('setValue', row.CustomerName);
    //        },
    //        columns: [[
    //            { field: 'Id', title: 'Id', hidden: true },
    //            { field: 'CustomerCode', title: '客户编号', width: 120, align: 'right' },
    //            { field: 'CustomerName', title: '客户名称', width: 150, align: 'right' }
    //        ]],
    //        fitColumns: true,
    //        filter: true,  // 启用搜索框
    //        //keyHandler: {
    //        //    up: function () { alert("up"); },
    //        //    down: function () { alert("down"); },
    //        //    enter: function () { alert("enter"); },
    //        //    query: function (keyword) {
    //        //        //alert(q);
    //        //        //动态搜索
    //        //        //$('#CustomerId').combogrid("grid").datagrid("reload", { 'CustomerName': keyword });
    //        //        //$('#CustomerId').combogrid("setValue", q);

    //        //        //设置查询参数
    //        //        var queryParams = $('#CustomerId').combogrid("grid").datagrid('options').queryParams;
    //        //        queryParams.CustomerName = keyword;
    //        //        $('#CustomerId').combogrid("grid").datagrid('options').queryParams = queryParams;
    //        //        //重新加载
    //        //        $('#CustomerId').combogrid("grid").datagrid("reload");

    //        //        //var row = $('#CustomerId').datagrid('getSelected');
    //        //        //$('#CustomerId').combogrid("setValue", row.CustomerId);
    //        //        //$("#CustomerName").val(row.CoustomerName);
    //        //        //将查询条件存入隐藏域
    //        //        $('#hdKeyword').val(keyword);
    //        //    }
    //        //}
    //    });
    //}

    //function InitSelectCustomer() {
    //    $('#SelectCustomer').combogrid({
    //        url: "/Customer/GetCustomerPageList",
    //        method: 'post',
    //        mode: 'remote',
    //        pageSize: 15,               //每页显示的记录条数，默认为10
    //        pageList: [10, 15, 20],       //可以设置每页记录条数的列表
    //        pagination: true,
    //        panelWidth: 500,
    //        toolbar: "#customerselecttoolbar",
    //        idField: 'Id',
    //        textField: 'CustomerName',
    //        columns: [[
    //            { field: 'Id', title: 'Id', hidden: true },
    //            { field: 'CustomerCode', title: '客户编号', width: 120, align: 'right' },
    //            { field: 'CustomerName', title: '客户名称', width: 150, align: 'right' }
    //        ]],
    //        fitColumns: true,
    //        filter: true  // 启用搜索框
    //    });
    //}

    function querycustomer() {
        $("#SelectCustomer").combogrid("grid").datagrid("reload", { "Customer": $("#SelectCustomerText").val() });
    }
    function querycustomer2() {
        $("#CustomerId").combogrid("grid").datagrid("reload", { "Customer": $("#SelectCustomerText2").val() });
    }

    function addLKZeroWarehouseContract2() {
        InitCustomer();
        InitChargingUnitCombobox();
        InitColdAlgorithmCombobox();
        $('#fm').form('clear');
        $('#dlg').dialog('open');
        url = '/LKWarehouseContract/AddLKZeroWarehouseContract';
    }

    function editLKZeroWarehouseContract() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要编辑的信息?');
            return;
        }
        window.location.href = "/LKWarehouseContract/EditLKZeroWarehouseContract?id=" + row.Id;
    }

    function delLKZeroWarehouseContract() {
        var row = $('#dg').datagrid('getSelected');
        if (!row) {
            Helper.Show('请选择需要删除的信息?');
            return false;
        }
        $.messager.confirm('提示信息', '您确认要删除吗?', function (r) {
            if (!r) { return false; }
            $.post("/LKWarehouseContract/DeleteLKZeroWarehouseContract", { id: row.Id }, function (json) {
                Helper.Show(json.Msg);
                if (json.Success) {
                    doSearch();
                }
            });
        });
    }

    function saveLKZeroWarehouseContract() {
        $('#fm').form('submit', {
            url: url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (json) {
                var json = eval('(' + json + ')');
                Helper.Show(json.Msg);
                if (json.Success) {
                    $('#fm').form('clear');
                    $('#dlg').dialog('close');
                    $('#dg').datagrid('reload');
                }
            }
        });
    }

    function formatter_IsValid(value, rowData, rowIndex) {
        return rowData.IsValid ? '启用' : '停用';
    }

    function formatter_IsByTon(value, rowData, rowIndex) {
        return rowData.IsByTon ? '是' : '否';
    }

    function formatter_ColdUnitPrice(value, rowData, rowIndex) {
        return rowData.ColdUnitPrice.toFixed(2);
    }

    function formatter_BeginTime(value, rowData, rowIndex) {
        return formatdate(rowData.BeginTime);
    }
    function formatter_EndTime(value, rowData, rowIndex) {
        return formatdate(rowData.EndTime);
    }
    function formatter_ContractTime(value, rowData, rowIndex) {
        return formatdate(rowData.ContractTime);
    }


</script>



